<?php

	// Functions and Class
	require_once 'framework/header.inc.php';
	
	// Set default page structure
	$page->constructor("home");
	
	// Scripts
	$script['jquery'] = array("jquery.js", "jquery.slider.js");
	$extended = "$('#slider').easySlider({auto:true, continuous:true, numeric:true, pause:15000});";
	$page->setScript($script,$extended);
	
	// Page title
	$page->default['pageTitle'] = $page->default['name'];
	
	// Last inserted books
	$sql = mysql_query("SELECT book_id, book_author_id, book_volume, book_title, book_description, date_format(book_post_date , '%e |%M| %Y') as book_post_date
						FROM book WHERE book_access != '0' ORDER BY book_id DESC LIMIT 6");

	if (mysql_num_rows($sql) > 0) {

		while ($row = mysql_fetch_assoc($sql)) {
			
			$spliter = (empty($row['book_volume'])) ? 540 : 440;
			$row['book_description'] = strip_tags(substr($row['book_description'], 0, $spliter))."..";
			$row['book_author'] = implode(mysql_fetch_assoc(mysql_query("SELECT author_name FROM author WHERE author_id=".$row['book_author_id']."")));
			$row['book_link'] = "library/book.php?id=".$row['book_id'];
			$lastbooks[] = $row;
		}
	}

	// Top story
	$topstory = $lastbooks[0];
	$topstory['book_description'] = substr($topstory['book_description'], 0, 300)."..";
	unset($lastbooks[0]);	// Remove topstory from array
	

	// Last inserted comunity nodes
	$sql = mysql_query("SELECT blog_id, blog_user_id, blog_title, date_format(blog_post_date , '%e |%M| %Y') as blog_post_date
						FROM blog WHERE blog_access != '0' ORDER BY blog_post_date DESC LIMIT 5");

	if (mysql_num_rows($sql) > 0) {

		while ($row = mysql_fetch_assoc($sql)) {
			
			$row['blog_author'] = implode(mysql_fetch_assoc(mysql_query("SELECT user_name FROM user WHERE user_id='".$row['blog_user_id']."'")));
			$row['blog_link'] = "blogs/blog.php?id=".$row['blog_id'];
			$blogs[] = $row;
		}
	}
	
	
	// News and press
	$sql = mysql_query("SELECT news_id, news_title, news_content, date_format(news_post_date , '%e |%M| %Y') as date
						FROM news ORDER BY news_post_date LIMIT 5");

	if (mysql_num_rows($sql) > 0) {

		while ($row = mysql_fetch_assoc($sql)) {

			$row['title'] = $row['news_title']."\n<span>".strip_tags(substr($row['news_content'], 0, 140))."..</span>";
			$row['link'] = "project/news.php?id=".$row['news_id'];
			$row['lead'] = $row['date'];
			$news[] = $row;
		}
	}
	
	$media = array("src" => $page->url['root']."media/dielli.swf", "width" => "500px", "height" => "200px");
	$donate = array("link" => "project/donation.php","src" => $page->url['styles'].$page->default['style']."/donate.gif", "width" => "200px", "height" => "80px");
	
	// Page render
	$page->render("CATEGORY",$page->category());
	$page->render("FOOTMENU",$page->navigation("footmenu"));
	$page->render("TOPSTORY",$topstory);
	$page->render("BOOKSLIDER",$lastbooks);
	$page->render("TOPBOOKS",topbooks(null,10));
	$page->render("BLOGBOX",$blogs);
	$page->render("MEDIABOX",$media);
	$page->render("DONATE",$donate);
	$page->render("NEWS",$news);

	
	// Display all
	$page->show();
?>